<%- include myCenterHeader.ejs%>

<div style="">
   <!---->
    <!--<div style="margin-top: 50px;font-size: 18px;text-align:center;line-height: 45px;width: 15%;height: 45px;float: left;background-color: #d77a03;-moz-border-radius: 5px;-webkit-border-radius: 5px;">-->
        <!--<a href="#addSchedule" data-toggle="modal" style="color: white;text-decoration: none">加为语伴</a>-->
        <!--<div class="modal hide fade" id="addSchedule" style="text-align: left">-->
            <!--<div class="modal-header">-->
                <!--<a href="#" class="close" data-dismiss="modal"></a>-->
                <!--<h4>验证信息</h4>-->
            <!--</div>-->
            <!--<form class="form-horizontal" method="post" action="/addPartner">-->
                <!--<div style="margin: 40px">-->
                    <!--<input type="hidden" name="respondentUser" value="<%- data._id %>">-->
                    <!--<input type="hidden" name="username" value="<%- data.username %>">-->
                    <!--<textarea name="applyMessage" placeholder="请输入验证信息" rows="3" style="width: 80%"></textarea>-->
                <!--</div>-->
                <!--<div class="modal-footer">-->
                    <!--<button type="submit" class="btn btn-primary">发送</button>-->
                <!--</div>-->


            <!--</form>-->
        <!--</div>-->

    <!--</div>-->
    <div style="clear: both;margin-top: 50px;margin-left: 5%">
        <div id='calendar' style="margin-top: 20px;"></div>
    </div>

    <div style="clear: both"></div>



</div>
<%- include myCenterFooter.ejs%>
<script>



    $(function(){
        var currentLangCode = '<%= __('partnerCenter').language %>';

        // build the language selector's options
        $.each($.fullCalendar.langs, function(langCode) {
            $('#lang-selector').append(
                    $('<option/>')
                            .attr('value', langCode)
                            .prop('selected', langCode == currentLangCode)
                            .text(langCode)
            );
        });

        // rerender the calendar when the selected option changes
        $('#lang-selector').on('change', function() {
            if (this.value) {
                currentLangCode = this.value;
                $('#calendar').fullCalendar('destroy');
                renderCalendar();
            }
        });

        function renderCalendar() {
            $('#calendar').fullCalendar({
                dayClick: function(date, allDay,jsEvent, view) {//data:当前时间，jsEvent:js信息：如坐标，view：当前视图对象：月：周：日
                    alert('<%= __('other').alert %>')
//                    var selDate=date.add(1).format();
//                    $.fancybox({//调用fancybox弹出层
//                        'type':'ajax',
//                        'href':'/event?date='+selDate
//                    });
                },
                eventClick: function(calEvent, jsEvent, view) {
                    if(calEvent.color=='red'){
                        alert('<%= __('other').alert2 %>')
                        return;
                    }
                    //calEvent:日历信息
                    var title=calEvent.title;
                    var start=calEvent.start.format()
                    var end=calEvent.end?calEvent.end.format():undefined;
                    var _id=calEvent._id;

                    $.fancybox({//调用fancybox弹出层
                        'type':'ajax',
                        'href':'/orderForm?_id='+_id,
                        padding:0
                    });

                },
                eventMouseover: function(calEvent, jsEvent, view) {
                    Date.prototype.format = function (fmt) { //author: meizz
                        var o = {
                            "M+": this.getMonth() + 1, //月份
                            "d+": this.getDate(), //日
                            "h+": this.getHours(), //小时
                            "m+": this.getMinutes(), //分
                            "s+": this.getSeconds(), //秒
                            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                            "S": this.getMilliseconds() //毫秒
                        };
                        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
                        for (var k in o)
                            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                        return fmt;
                    }

                    if(!calEvent.allDay){
                        var fstart  = (new Date(calEvent.start.format().replace(/T/g,' '))).format('hh:mm');
                        if(calEvent.end){
                            var fend  = (new Date(calEvent.end.format().replace(/T/g,' '))).format('hh:mm');
                            $(this).attr('title', fstart + " - " + fend + " " + calEvent.title);
                        }else{
                            $(this).attr('title', fstart+ " " + calEvent.title);
                        }
                    }else{
                        $(this).attr('title', calEvent.title);
                    }

//                    $(this).css('font-weight', 'normal');
//                    $(this).tooltip({
//                        effect:'toggle',
//                        cancelDefault: true
//                    });
                },

                header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month,agendaWeek,agendaDay'
                },
                defaultView:'agendaWeek',
                //添加
//                theme: false,//使用jquery-ui来生成界面
//                editable: true,
//                allDaySlot : false,
//                defaultDate: '2014-09-12',
                lang: currentLangCode,
//                buttonIcons: false, // show the prev/next text
//                weekNumbers: true,
//                editable: true,
//                eventLimit: true ,// allow "more" link when too many events
                //

                events:function(start,end){
                    //$("#calendar").fullCalendar('removeEvents');
                    $.ajax({
                        url:'/partnerSchedule?start='+start.format()+'&end='+end.format()+'&id=<%- data.id%>',

                        success:function(doc){
                            eval('var j='+doc);
                            var events=[];
                            for(var i=0;i< j.length;i++){
                                var ev=j[i];
                                if(ev.end){
                                    var event={
                                        title:ev.title,
                                        start:ev.start,
                                        end:ev.end,
                                        _id:ev._id,
                                        color:ev.color
                                    }
                                    $("#calendar").fullCalendar('renderEvent',event,false)
                                    // alert('1111');
                                }else{
                                    var event={
                                        title:ev.title,
                                        start:ev.start,
                                        _id:ev._id,
                                        color:ev.color
                                    }
                                    $("#calendar").fullCalendar('renderEvent',event,false)
                                    //alert('222222');
                                }
                            }
                        }
                    })
                },
                eventTextColor:'#000000'        //字体颜色
            });
        }

        renderCalendar();

    })


</script>
